package test.hystrix.client;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandKey;

public class CacheCommand extends HystrixCommand<String>{
    private String cacheKey;
    private CloseableHttpClient httpClient;
	protected CacheCommand(String cacheKey) {
		 super(
			Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("exempleGroup")).andCommandKey(HystrixCommandKey.Factory.asKey("myCache"))
				 );
		 this.cacheKey = cacheKey;
	}
	
	

	@Override
	protected String getCacheKey() {
		// TODO Auto-generated method stub
		return this.cacheKey;
	}



	@Override
	protected String run() throws Exception {
		httpClient = HttpClients.createDefault();
		//处理参数
		try {
			HttpGet httpget =new HttpGet("http://localhost:8080/normalVisit");
			HttpResponse response = httpClient.execute(httpget) ;
			return EntityUtils.toString(response.getEntity());
		}catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
